<?php
/*
 * Created on 2016/11/20
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
  require_once('../db/properties.inc.php');
  session_start();
  $userInfo = $_SESSION["userInfo"]; 
  if(!$userInfo){
 	header("Location: ../../view/login.html");
 	exit;
  }
  
  $userObj = json_decode($userInfo);//用户信息
  $content = $_POST["content"];//回复内容
  $titleId = $_POST["titleId"];//回复主题id
  $nowDate =  date('Y-m-d H:i:s',time());//当前时间
   try {
	   	 //保存回复
		 $conn = new mysqli($url, $user, $pwd, $dbname, $port);
		 $conn -> set_charset("utf8");
		 
		 if (mysqli_connect_errno()) {
		 	header("Location: ../../view/content.php?id=".$titleId);
		    exit;
		 }
		$sqlTitle = "INSERT INTO bolggerReply (titleId,userId,reply,addTime) VALUES(?,?,?,?)";
		//插入主表
		$mysqli_stmt=$conn->prepare($sqlTitle);
		//第一个参数表明变量类型，有i(int),d(double),s(string),b(blob)
		$mysqli_stmt->bind_param('iiss',$titleId,$userObj->id,$content,$nowDate);
		//执行预处理语句
		$mysqli_stmt->execute();
		
		$conn->close();
		header("Location: ../../view/content.php?id=".$titleId);
		exit;
	}catch( Exception $e ) {
		header("Location: ../../view/content.php?id=".$titleId);
		exit;
	}
?>
